<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class AdminRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' =>Rule::unique('users')->where(function ($query) {
                $query->whereNull('deleted_at')->where('id', '!=', $this->id);
            }),
            'email' =>Rule::unique('users')->where(function ($query) {
                $query->whereNull('deleted_at')->where('id', '!=', $this->id);
            })
        ];
    }
    public function messages()
    {
        return [
            'name.unique' => '该用户名已经被注册过了',
            'email.unique' => '该邮箱已经被注册过了'
        ];
    }
}
